package com.kfirszt.elearning.utils;

import java.util.Enumeration;
import java.util.Locale;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import org.apache.struts2.ServletActionContext;

public class SessionUtil {
	
	public static Object getSessionAttribute(String attributeName){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			HttpSession session = request.getSession();
			if(session==null) return null;
			return session.getAttribute(attributeName);
		} catch (Exception e) {
			return null;
		}
	}

	
	public static void putSessionAttribute(String name, Object value){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			HttpSession session = request.getSession();
			if(session==null) return;
			session.setAttribute(name, value);
		} catch (Exception e){
		}
	}
	
	public static void removeSessionAttribute(String name){
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			HttpSession session = request.getSession();
			if(session==null) return;
			session.removeAttribute(name);
		} catch (Exception e){
		}
	}
	
	public static Enumeration<String> getAttributesNames() {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			HttpSession session = request.getSession();
			if(session==null) return null;
			return session.getAttributeNames();
		} catch (Exception e){
		}
		return null;
	}
	
	public static Locale getUserBrowserLocale() {
		try {
			HttpServletRequest request = ServletActionContext.getRequest();
			return request.getLocale();
		} catch (Exception e) {
			return Locale.getDefault();
		}
	}

}
